/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package limousine.report;

import java.sql.Connection;
import java.util.HashMap;
import javax.servlet.ServletContext;
import javax.sql.DataSource;
import net.sf.jasperreports.engine.JasperRunManager;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 *
 * @author TEComp
 */
public class PrintConfirm {

    public PrintConfirm() {
    }
    
    public byte[] printConfirm(ServletContext context) {
        byte[] bytes = null;
        try {
            DataSource dataSource = (DataSource) WebApplicationContextUtils.getWebApplicationContext(
                    context).getBean("dataSource");
            Connection connection = dataSource.getConnection();
            HashMap jasperParameter = new HashMap();
            bytes = JasperRunManager.runReportToPdf(
                    this.getClass().getResourceAsStream("./confirmation.jasper"),
                    jasperParameter, connection);
            connection.close();
            return bytes;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return bytes;
    }
}
